<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/jsp/include/taglib.jsp"%>
<%@ include file="/jsp/include/headform.jsp"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<html>
	<head>
		<base href="<%=basePath%>" />
		<title>NAV</title>
		<LINK href="${ctxStatic}/css/style_chron.css" type="text/css"
			rel="stylesheet">
		<script type="text/javascript">
		Global.ticket = ${sessionScope.LOGIN_USER.id}+'_'+1;
		Global._ruleTypeId = 1;
		Global._pType = 'user';
		Global._nType = 'resource';
		$(function() {
			
			var pid = getUrlParam('menuId');
			var hasAllPri = getUrlParam('hasAllPri');
			Global.permissionIds = getUrlParam('permissionIds')+",";
			
			$.ajax({
				   url:'api/resource/'+pid+'/tree?ticket='+Global.ticket ,
				   type:'get',
				   dataType:'json',
				   async:false,
				   error:function(){alert('系统连接失败，请稍后再试！')},
				   success:function(result){
					   var _title="";
					   if(result.info.success==false){
	 					   alert('系统异常！');
	 				   }else{
	 					  var data = result.data;
							if(data != null){
								for(var i = 0 ; i < data.length ; i ++){
									var d = data[i];
	
									if(hasAllPri=='true'){
										if(d.pid == pid){
											_title += "<div class=\"menu_2\" id=\"menu\" onclick=\"javascript:doMenu("+d.nid+");\"";
											_title += "style=\"cursor: pointer; font-size: 12px; font-weight: 400; font-style: normal; color: #000000; margin: 5px;\"";
											_title += "onmouseover=\"style.color='#FA6C27';\" onmouseout=\"style.color='#000000';\">"+d.node.name+" </div>";
											_title += getSubMenu(data, d.nid, hasAllPri);
										}
									}else{
										if(d.pid == pid/*  && Global.permissionIds.indexOf(d.nid+",")>=0 */){
											var _subTitle = getSubMenu(data, d.nid, hasAllPri);
											if(_subTitle){
												_title += "<div class=\"menu_2\" id=\"menu\" onclick=\"javascript:doMenu("+d.nid+");\"";
												_title += "style=\"cursor: pointer; font-size: 12px; font-weight: 400; font-style: normal; color: #000000; margin: 5px;\"";
												_title += "onmouseover=\"style.color='#FA6C27';\" onmouseout=\"style.color='#000000';\">"+d.node.name+" </div>";
												_title += _subTitle;											
											}
										}
									}
								}
							}
	 				   }
				  	  $("#firstMenu").append(_title);	
				   }
			   });
			});
	    
		// 获取url中的参数
		   function getUrlParam(name) {
		   	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
		   	var r = window.location.search.substr(1).match(reg); // 匹配目标参数
		   	if (r != null)
		   		return unescape(r[2]);
		   	return null; // 返回参数值
		   }
		   
		//获取三级子资源菜单
		    function getSubMenu(data, pid, hasAllPri) {
		    	var _title="";
		    	var isExist = false;
		    	_title += "<div id=\"submenu"+pid+"\" class=\"submenu\" style=\"display: none; margin-left: 5px; margin-top: -6px;\">";
				_title += "<table width=\"181\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
				_title += "<tr><td background='${ctxStatic}/images/page/menu_29.jpg'>";
				_title += "<div style=\"height: 180px; overflow: auto; margin-left: 15px;\">";
		    	for(var i = 0 ; i < data.length ; i ++){
	    			var d = data[i];
					if(hasAllPri=='true'){
						if(d.pid == pid){
							_title += "<div class=\"menu_drop\" style=\"width: 155px; margin-left: -15px;\">";
							_title += "<dt>";
							_title += "<span><a href=\"#\" onclick=\"javascript:top.selectLevel4Menu("+d.nid+",'"+d.node.path+"');return false;\">&nbsp;&nbsp;"+d.node.name+"";
							_title += "</span></a></dt></div>";
						}
					}else if(d.pid == pid && Global.permissionIds.indexOf(d.nid+",")>=0){
						_title += "<div class=\"menu_drop\" style=\"width: 155px; margin-left: -15px;\">";
						_title += "<dt>";
						_title += "<span><a href=\"#\" onclick=\"javascript:top.selectLevel4Menu("+d.nid+",'"+d.node.path+"');return false;\">&nbsp;&nbsp;"+d.node.name+"";
						_title += "</span></a></dt></div>";
						isExist = true;
					}
				}
		    	_title += "</div></td></tr>";
				_title += "<tr><td><img src=\"${ctxStatic}/images/page/menu_30.jpg\" style=\"margin-top: -12px;\" width=\"181\" height=\"7\" />";
				_title += "</td></tr></table></div>"
		    	
				if(hasAllPri!='true' && !isExist){
					return '';
				}
			   	return _title; // 返回参数值
			 }
		    
			//清空左边菜单信息
			function clearNavPanel(panel){
				if(panel.items.length>0){
					var length = panel.items.length;
					for(var k = length;k > 0;k--){
						var index = panel.items.itemAt(k-1);
						index.ownerCt.remove(index, true);
					}
				}
			}		
			
			function doMenu(index){
				$(".submenu").hide();
				$("#submenu"+index).show();
			}
		</script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
	</head>
	<body scroll="no" background:#fff>
		<table width="98%" height="100%" border="0" cellpadding="0"
			cellspacing="0" style="margin-left: 10px;">
			<tr height="20" style="background: url(${ctxStatic}/images/page/tiao1.gif);background-repeat: no-repeat;"><td >
				</td></tr>
			<tr>
				<td id="firstMenu" valign="top" style="background: url(${ctxStatic}/images/page/tiao2.gif);background-repeat: repeat-y;height: 100%;margin: 0px;">
				 </td>
			</tr>
			<tr height="19"><td>
				<img src="${ctxStatic}/images/page/tiao3.gif">
			</td></tr>
		</table>
<!-- <script type="text/javascript"> -->
// <!--
// 	doMenu(1);
// -->
<!-- </script> -->
	</body>

</html>
